package QrCode

import (
	"github.com/skip2/go-qrcode"
	"go-barcode/internal/api"
	"image/color"
)

type QrCode struct {
}

func (qr *QrCode) Create(savePath, code string, img api.ImageCode) error {
	q, err := qrcode.New(code, qrcode.Medium)
	if err != nil {
		return err
	}
	size := img.Size.Width
	if size <= 0 {
		size = 256
	}
	q.DisableBorder = false //去掉边框
	if img.Color.Background == nil {
		q.BackgroundColor = color.White
	} else {
		q.BackgroundColor = img.Color.Background
	}
	if img.Color.Foreground == nil {
		q.ForegroundColor = color.RGBA{A: 255, B: 0, R: 0, G: 0}
	} else {
		q.ForegroundColor = img.Color.Foreground
	}
	//70*70一般手机最小能扫描的尺寸了  输出的文件名称:output.png
	err = q.WriteFile(size, savePath)
	return err
}
